package com.example.appcontact;

import java.util.LinkedHashMap;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

import com.example.adapter.A003BuchMeOAdapter;
import com.example.base.BaseTabActivity;
import com.example.model.Contacts;
import com.example.model.OutContacts;
import com.example.model.OutNotification;
import com.example.util.Util;

public class A003BuchMeOContact extends BaseTabActivity implements
		OnItemLongClickListener, OnItemClickListener {
	private static final String TAG = "A003BuchMeOContact";

	private static final int TYPE_GET_PROFILE = 0;

	private List<Contacts> mContacts;
	private OutContacts outContacts;
	private ListView mListView;
	private A003BuchMeOAdapter mAdapter;

	private Context mContext;
	private String mEmail;
	private OutNotification outNotifications;

	private View layout_profile;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initView();
	}

	@Override
	protected void onStart() {

		// refresh();
		super.onStart();
	}

	@Override
	protected void onResume() {

		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	private void initView() {
		setContentView(R.layout.a003_listview_buchmeo);
		this.mContext = this;
		this.mListView = (ListView) this.findViewById(R.id.a003_listview);
		this.mListView.setOnItemLongClickListener(this);
		this.mListView.setOnItemClickListener(this);
		
	}

	private void initData(List<Contacts> outContacts) {
		mContacts = outContacts;
		mAdapter = new A003BuchMeOAdapter(getParent(),
				R.layout.item_a003_buchmeo, mContacts);
		this.mListView.setAdapter(mAdapter);
	}

	@Override
	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		Util.callPhone(getParent(), mContacts.get(arg2).getPhoneNumber());
		return false;
	}

	@Override
	public void notificationRefresh(List<Contacts> contacts) {
		Log.d("A003BuchmeO contacts", "contact size :" + contacts.size() + contacts.toString());
		initData(contacts);
	}

	@Override
	public void notificationGetNotifi(List<String> email) {

	}

	

	

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		final Contacts data = mContacts.get(arg2);
		if (data != null) {
         Intent inew = new Intent(this,A004DetailContact.class);
         inew.putExtra("item", data);
         startActivity(inew);
		}
	}
}
